// pages/employees/employees.js
var common = require('../../js/common.js');
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    yiyuan_id: 0,
    yisheng: [],
    hushi: [],
    qiantai: [],
    yuanzhang: [],
    hidden: true,
    nocancel: true
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.setData({
      yiyuan_id: 0,
      yisheng: [],
      hushi: [],
      qiantai: [],
      yuanzhang: [],
      hidden: true,
      nocancel: true,
      yiyuan_id: wx.getStorageSync('yiyuan_id'),
      yjyz: wx.getStorageSync('userInfo').type,
      user_id: wx.getStorageSync('userInfo').id
    })
    wx.setNavigationBarTitle({
      title: '同事列表'
    })
    this.getdatalist();
  },
  getdatalist: function() {
    var yiyuan_id = this.data.yiyuan_id;
    //获取员工列表
    var url = app.globalData.localUrl + 'yuangonglist';
    var that = this;
    wx.request({
      url: url,
      data: {
        id: yiyuan_id,
      },
      header: {
        'content-type': 'application/json'
      },
      success: function(a) {
        console.log(a);
        if (a.data.code == 1) {
          if (a.data.data[1]) {
            that.setData({
              yisheng: a.data.data[1],
            })
          }
          if (a.data.data[2]) {
            that.setData({
              hushi: a.data.data[2],
            })
          }
          if (a.data.data[3]) {
            that.setData({
              qiantai: a.data.data[3],
            })
          }
          if (a.data.data[4]) {
            that.setData({
              yuanzhang: a.data.data[4],
            })
          }

        } else {
          wx.showToast({
            title: '暂无数据',
            icon: 'loading',
            duration: 2000
          })
        }
      }
    })
  },
  //查看邀请码
  yaoqingma: function() {
    wx.navigateTo({
      url: '/pages/yaoqingma/yaoqingma',
    })
  },
  //编辑权限
  quanxian: function() {
    wx.navigateTo({
      url: '/pages/quanxian/quanxian',
    })
  },
  //数据统计
  tongji: function() {
    wx.navigateTo({
      url: '/pages/tongji/tongji',
    })
  },
  //添加预约
  addyy: function() {
    wx.navigateTo({
      url: '/pages/addyy/addyy',
    })
  },
  //编辑
  bianji: function (e) {
    console.log("id =" + e.target.dataset.id)
    var id = e.target.dataset.id;
    wx.navigateTo({
      url: '/pages/clinicedit3/clinicedit3?id=' + id,
    })
  },
  //删除员工
  shanchu: function (e) {
    var id = e.target.dataset.id;
    this.setData({
      hidden: false,
      delid: id
    });
  },
  cancel: function () {
    this.setData({
      hidden: true
    });
  },
  confirm: function () {
    this.setData({
      hidden: true
    });

    var that = this;
      //删除员工
    // console.log('删除员工id', that.data.delid)
      common.request(app.globalData.localUrl, 'delyuangong', {
        id: that.data.delid
      },
        function (res) {
          console.log('删除员工', res)
          if (res.data.code == 1) {
            console.log('刷新本页面', res)
            wx.redirectTo({
              url: '/pages/employees/employees',
            })
            // that.getdatalist();
          }
        }, 'rtype= post');



  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    var that = this;
    //获取积分
    common.request(app.globalData.localUrl, 'authuser', {
        yiyuan_id: wx.getStorageSync('yiyuan_id'),
        user_id: wx.getStorageSync('userInfo').id
      },
      function(res) {
        console.log('权限列表', res)
        // console.log(res.data.data.gsy_status)
        that.setData({
          quanxian: res.data
        })
      }, 'rtype= post');
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})